<?php
class Game
{
    private $territories = array();
    private $units = array();
    private $players = array();
    private $commands = array();
	
    public function initializeGame()
    {
        $this->players = $this->initializePlayers();
        $this->territories = $this->initializeTerritories();
        $this->units = $this->initializeUnits($this->territories,
                                              $this->players);
        $this->commands = $this->getCommands($this->units);

        foreach($this->units as $unit) {
            echo $unit->getInfo();
        }
        $phase = new PhaseOrder($this->commands);
        $phase->checkCommands();


        
        foreach($this->units as $unit) {
            echo $unit->getInfo();
        }
    }
	
    public function getCommands($units)
    {
        $commands = array();
        $commands[0] = new CommandMove($units[0], $this->territories[1]);
        $commands[1] = new CommandMove($units[1], $this->territories[1]);
        return $commands;
    }

    /**
     * @todo Daten aus DB holen
     * @return Player
     */
    private function initializePlayers()
    {
        $players = array();
        $players[0] = new Player(0, "Flo", null, null);
        $players[1] = new Player(1, "Steph", null, null);
        return $players;
    }

    private function initializeTerritories()
    {
        $territories = array();
        $territories[0] = new Country("Kiel", "Kie", 500, 500, array(), array(), false);
        $territories[1] = new Country("Spanien", "Spa", 64, 538, array(), array(), false);
        $territories[2] = new Country("Portugal", "Por", 620, 563, array(), array(), false);
        $territories[3] = new Country("Gascony", "Gas", 192, 510, array(), array(), false);
        $territories[4] = new Country("Marseilles", "Mar", 268, 531, array(), array(), false);
		
        return $territories;
    }

    private function initializeUnits($territories, $players)
    {
        $units = array();
        $units[0] = new Army($territories[2], $players[0]);
        $units[1] = new Army($territories[4], $players[1]);

        return $units;
    }
}
?>